home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI727.ASC < prev    next >
Text File  |  1992-02-25  |  1KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  727
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/1
  12.  
  13.     TITLE  :  Redirecting Output Before Spawn
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.   /************************************************************
  24.    How to redirect output before spawning a child process.
  25.    ************************************************************/
  26.  
  27.   FILE *fp;
  28.   int handle;
  29.  
  30.   fp=fopen( <parms. to open file where to redirect stdout> );
  31.   /* in this case, use "NUL" as the file, this is DOS's NULL device
  32.   */
  33.  
  34.   handle=dup(fileno(stdout));
  35.   dup2(fileno(fp),fileno(stdout));
  36.   execlp ( <whatever parameters you need> );
  37.   dup2(handle,fileno(stdout));
  38.  
  39.   /*This will duplicate the file handle stdout to the FILE pointer
  40.   fp. Then dup2 is used to replace stdout with the new file opened
  41.   with fopen. Next, make your call to spawn. Finally, use dup2 with
  42.   the saved handle variable to restore stdout. */
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.